/* @flow */

// 1.用读nodejs的方式来读源码
// 2.读函数，关键点是三点1.传了哪些参数2.返回什么结果3.干了哪些事情
/**
 *
 *
 *
 *
 *
 *
 */
import { parse } from './parser/index'
import { optimize } from './optimizer'
import { generate } from './codegen/index'
import { createCompilerCreator } from './create-compiler'

// `createCompilerCreator` allows creating compilers that use alternative
// parser/optimizer/codegen, e.g the SSR optimizing compiler.
// Here we just export a default compiler using the default parts.
export const createCompiler = createCompilerCreator(function baseCompile (
  template: string,
  options: CompilerOptions
): CompiledResult {
  const ast = parse(template.trim(), options)
  if (options.optimize !== false) {
    optimize(ast, options)
  }
  const code = generate(ast, options)
  // 返回
  /**
   * 1.ast对象
   * 2.
   *
   *
   *
   *
   */
  return {
    ast,
    render: code.render,
    staticRenderFns: code.staticRenderFns
  }
})
